package Zookeeper;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;
import java.util.List;

/**
 * @Author lixinlei
 * @Date 2023/3/27 10:54
 */
public class ZKConnection {


    public static void main(String[] args) throws Exception {

        String connectString = "node101:2181,node102:2181,node103:2181";
        int sessionTimeout = 10000;

        ZooKeeper zkClient = new ZooKeeper(connectString, sessionTimeout, new Watcher() {
            @Override
            public void process(WatchedEvent event) {

                System.out.println("事件类型"+event.getType());
                System.out.println("事件路径"+event.getPath());
                System.out.println("事件状态"+event.getState());

            }
        });


        List<String> children = zkClient.getChildren("/",false);
        System.out.println(children);

        zkClient.close();
    }


}
